/**
 * 新增或修改附件的输入窗口
 */
Ext.namespace("Ext.ux.sysfile");

Ext.ux.sysfile.FileDetailWindow = Ext.extend(Ext.Window, {

	width: 780,
	height: 460,
	layout: 'fit',
	plain : true,
	modal: true,
	border: false,
	
	detailPanel: null,

	initComponent:function(){
		Ext.ux.sysfile.FileDetailWindow.superclass.initComponent.call(this);
		
		// 编辑附件数据时的JSON解析
		var formReader = new Ext.data.JsonReader({
			root: 'result',
			totalProperty: 'totalCount',
			id : 'sysFileId'
		},[
			{name: 'sysFileId', mapping: 'sysFileId'}, 
			{name: 'entity', mapping: 'entity'}, 
			{name: 'entityId', mapping: 'entityId'}, 
			{name: 'fileCode', mapping: 'fileCode'},
			{name: 'fileName', mapping: 'fileName'},
			{name: 'fileSize', mapping: 'fileSize', type: 'int'},
			{name: 'fileType', mapping: 'fileType'},
			{name: 'filePath', mapping: 'filePath'},
			{name: 'fileFormat', mapping: 'fileFormat'},
			{name: 'cmp', mapping: 'cmp'},
			{name: 'cdt', mapping: 'cdt', type: 'date', dateFormat: 'Y-m-d'},
			{name: 'eemp', mapping: 'eemp'},
			{name: 'edt', mapping: 'edt', type: 'date', dateFormat: 'Y-m-d'},
			{name: 'memo1', mapping: 'memo1'},
			{name: 'memo2', mapping: 'memo2'}
		]);

	
		var fileInputPanel = new Ext.form.FormPanel({
    		labelAlign: 'right',
       		frame: true,
       		reader: formReader,
        	bodyStyle: 'padding:5px 5px 0',
       		width: 300,
       		items: [{
       		 	layout: 'form',
       		 	xtype: 'fieldset',
		        title: '<span class="fs_tip">请输入附件基本信息，标志 <span class="fs_flag">*</span> 字段为必填项</span>',
	       		items:[{
	       			layout: 'column',
		       		items:[{
		       			columnWidth: .5,
		       			layout: 'form',
		       			items: [{
							xtype: 'hidden',
							name: 'id'
						},{
			       			fieldLabel: '<span class="fs_flag">*</span>&nbsp;值对象名称',
			       			name: 'entity',
			       			xtype: 'textfield',
			       			allowBlank: false,
							maxLength: 25,
			       			anchor: '95%'
		       		 	}]
		       		},{
		       			columnWidth: .5,
		       			layout: 'form',
		       			items: [{
		       		 		fieldLabel: '<span class="fs_flag">*</span>&nbsp;值对象主键',
		       		 		name: 'entityId',
		       		 		xtype: 'textfield',
		       		 		allowBlank: false,
							minValue: 1,
							decimalPrecision: 0,
		       		 		anchor: '95%'
		       			}]
		       		}]},{
		       		 	layout: 'column',
		       		 	items:[{
			       			columnWidth: .5,
			       		 	layout: 'form',
			       		 	items: [{
			       		 			fieldLabel: '<span class="fs_flag">*</span>&nbsp;附件编号',
				       		 		xtype: 'textfield',
				       		 		name: 'fileCode',
				       		 		allowBlank: false,
									maxLength: 25,
				       		 		anchor: '95%'
			       		 		}]
			       		 	},
		 					{
			       		 		columnWidth: .5,
			       		 		layout: 'form',
			       		 		items: [{
			       		 			fieldLabel: '<span class="fs_flag">*</span>&nbsp;附件名称',
				       		 		xtype: 'textfield',
				       		 		name: 'fileName',
									maxLength: 50,
				       		 		anchor: '95%'
			       		 		}]
		       		 		}]
	       		 	},{
	       		 	layout: 'column',
		       		 	items:[{
		       		 		columnWidth: .5,
		       		 		layout: 'form',
		       		 		items: [{
		       		 			xtype: 'sysCodeCombo',
								hiddenName:'fileType',
								typeCode:'ABF_FILE_TYPE',
		       		 			fieldLabel: '附件类型',
			       		 		anchor: '95%'
		       		 		}]
		       		 	},{
		       		 		columnWidth: .5,
		       		 		layout: 'form',
		       		 		items: [{
		       		 		    fieldLabel: '附件格式',
		       		 			xtype: 'sysCodeCombo',
								hiddenName:'fileFormat',
								typeCode:'ABF_FILE_TYPE',
		       		 			anchor: '95%'
		       		 		}]
		       		 	}]
	       		 	},{
		       		 	layout: 'column',
		       		 	items:[{
		       		 		columnWidth: .5,
		       		 		layout: 'form',
		       		 		items: [{
		       		 			fieldLabel: '附件大小',
			       		 		xtype: 'numberfield',
			       		 		minValue: 1,
								decimalPrecision: 0,
			       		 		name: 'fileSize',
			       		 		anchor: '95%'
		       		 		}]
		       		 		
		       		 	}]
	       		 },{
		       		 	layout: 'column',
		       		 	items:[{
		       		 		columnWidth: 1,
		       		 		layout: 'form',
		       		 		items: [{
		       		 		   	fieldLabel: '附件路径',
		       		 			xtype: 'textfield',
		       		 			name: 'filePath',
		       		 			allowBlank: false,
		       		 			maxLength: 400,
		       		 			anchor: '97%'
		       		 		}]
		       		 	}]
	       		 },{
		       		 	layout: 'column',
		       		 	items:[{
		       		 		columnWidth: .5,
		       		 		layout: 'form',
		       		 		items: [{
		       		 			fieldLabel: '创建人',
			       		 		xtype: 'textfield',
			       		 		name: 'cmp',
			       		 		anchor: '95%'
		       		 		}]
		       		 		
		       		 	},{
		       		 		columnWidth: .5,
		       		 		layout: 'form',
		       		 		items: [{
		       		 			fieldLabel: '创建时间',
			       		 		xtype: 'datefield',
			       		 		format: 'Y-m-d H:i:s',
			       		 		name: 'cdt',
			       		 		anchor: '95%'
		       		 		}]
		       		 	}]
	       		 },{
		       		 	layout: 'column',
		       		 	items:[{
		       		 		columnWidth: .5,
		       		 		layout: 'form',
		       		 		items: [{
		       		 			 fieldLabel: '修改人',
			       		 		xtype: 'textfield',
			       		 		name: 'eemp',
			       		 		anchor: '95%'
		       		 		}]
		       		 		
		       		 	},{
		       		 		columnWidth: .5,
		       		 		layout: 'form',
		       		 		items: [{
		       		 			fieldLabel: '修改时间',
			       		 		xtype: 'datefield',
			       		 		format: 'Y-m-d H:i:s',
			       		 		name: 'edt',
			       		 		anchor: '95%'
		       		 		}]
		       		 	}]
	       		 },{
		       		 	layout: 'column',
		       		 	items:[{
		       		 		columnWidth: 1,
		       		 		layout: 'form',
		       		 		items: [{
		       		 			fieldLabel: '备注1',
			       		 		xtype: 'textarea',
			       		 		name: 'memo1',
			       		 		anchor: '97%'
		       		 		}]
		       		 		
		       		 	},{
		       		 		columnWidth: 1,
		       		 		layout: 'form',
		       		 		items: [{
		       		 			fieldLabel: '备注2',
			       		 		xtype: 'textarea',
			       		 		name: 'memo2',
			       		 		anchor: '97%'
		       		 		}]
		       		 	}]
	       		 }]
       		 }],
       		 buttons: [{
				text: '&nbsp;&nbsp;保存',
				width: 90,
				iconCls: 'icon-middle-save',
				scale: 'medium',
				handler: this.save,
				scope: this
			},{
				text: '&nbsp;&nbsp;关闭窗口',
				width: 90,
				iconCls: 'icon-middle-cancel',
				scale: 'medium',
				handler: function(){
					this.close();
				},
				scope: this
			}]
    	});
		
    	this.add(fileInputPanel); 
    	this.detailPanel = fileInputPanel;
	},
	
	//保存
    save: function(){
    	if(this.detailPanel.form.isValid()){
    		this.detailPanel.form.submit({
    			url: 'sys-file!save.action',
    			success: function(form, action) {
    				Ext.getCmp('fileQueryPanel').search();
    				this.close();
					Ext.Msg.alert('系统提示', '成功更新附件信息！');
				},
				failure: function(form, action) {
					Ext.Msg.alert('系统提示', '更新附件信息失败！');
				},
				reset: true,	// 是否需要清空表单
				waitMsg : '正在保存数据，请稍候...',
				scope: this
    		});
    	}
    },
	
	//加载附件数据
	loadById: function(sysFileId){
		this.detailPanel.form.load({
			url: 'sys-file!input.action?sysFileId=' + sysFileId,
			waitMsg: '正在载入数据...',
			failure: function() {
				Ext.Msg.alert('系统提示', '无法加载指定附件信息！');
			}
		});
		this.show();
	}

});